package com.cy.store.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * @PROJECT_NAME: store
 * @DESCRIPTION:
 * @USER: 28416
 * @DATE: 2022/11/10 17:41
 */
@Slf4j
@Component
@Aspect //标记为切面类
public class TimerAspect {

    @Around("execution(* com.cy.store.service.impl.*.*(..))")
    //定义切面方法
    public Object around(ProceedingJoinPoint pjp) throws Throwable {  //连接点  目标函数的对象
        //记录当前时间
        Long start = System.currentTimeMillis();
        Object result = pjp.proceed();//调用目标方法：login
        Long end =  System.currentTimeMillis();
        log.info("执行耗时:{}",(end-start));
        //后记录当前时间
        return result;
    }

}
